判断所给目录内哪些二级目录下没有text.txt文件。
有text.txt文件的二级目录,根据文件计算选项中单词数最大的值(选项间以|分割,单词间以空格分隔)。
假如脚本名字为1.sh, 运行脚本的格式为 ./1.sh 123 root,其中123为目录名字,而root为要计算数量的单词。
说明: 这个shell脚本题目出的有点歧义。 原题给的描述不是很清楚,我另外又改了一下需求,依然不是很清晰。在这里我再做一个补充: 对于有test.txt的目录,计算出该test.txt文件里面所给出单词的次数。不用找最大。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| #!/bin/bash if [ $# -ne 2 ] then echo "useage $0 dir word" exit 1 fi if [ -d $1 ] then cd $1 else echo "$1目录不存在" exit 1 fi for f in `ls $1` do if [ -d $f ] then if [ -f $f/test.txt ] then n=`grep -cw "$2" $f/test.txt` echo "$1/$f/test.txt 里面有$n个$2" else echo "$1/$f 下面没有test.txt" fi fi done
|